(() => {
  function greeter (person: string) {
    return 'Hello, ' + person
  }
  
  let user = 'Yee'
  // let user = 123 // error 
  
  console.log(greeter(user))
})()

;(() => {
  // 接口
  interface Person {  // API  interface
    firstName: string
    lastName: string
  }
  
  function greeter (person: Person) {
    return 'Hello, ' + person.firstName + ' ' + person.lastName
  }
  
  let user = {
    firstName: 'Yee223333444',
    lastName: 'Huang22333444'
  }
  
  console.log(greeter(user))
})()

;(() => {
  class User {
    fullName: string
    firstName: string
    lastName: string
  
    constructor (firstName: string, lastName: string) {
      this.firstName = firstName
      this.lastName = lastName
      this.fullName = firstName + ' ' + lastName
    }
  }
  
  interface Person {
    firstName: string
    lastName: string
  }
  
  function greeter (person: Person) {
    return 'Hello, ' + person.firstName + ' ' + person.lastName
  }
  
  let user = new User('Yee', 'Huang')
  
  console.log(greeter(user))
})()

/* 
TS的2个重要好处:
1. 补全提示(写正确代码)
2. 错误提示(错误代码)
*/